home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Freelog 125
/
Freelog_MarsAvril2015_No125.iso
/
Musique
/
Quod Libet
/
quodlibet-3.3.0-installer.exe
/
bin
/
quodlibet
/
qltk
/
songsmenu.pyc
(
.txt
)
< prev
next >
Wrap
Python Compiled Bytecode
|
2014-12-31
|
12KB
|
377 lines
# Source Generated with Decompyle++
# File: in.pyc (Python 2.7)
from gi.repository import Gtk
from quodlibet import qltk
from quodlibet.util import print_exc
from quodlibet.qltk.msg import WarningMessage
from quodlibet.qltk.delete import TrashMenuItem, trash_songs
from quodlibet.qltk.information import Information
from quodlibet.qltk.properties import SongProperties
from quodlibet.qltk.x import SeparatorMenuItem, Button
from quodlibet.qltk import get_top_parent
from quodlibet.util import connect_obj
from quodlibet.plugins import PluginManager, PluginHandler
from quodlibet.plugins.songsmenu import SongsMenuPlugin
from quodlibet.util.songwrapper import ListWrapper, check_wrapper_changed
class ConfirmMultiSongInvoke(WarningMessage):
'''Dialog to confirm invoking a plugin with X songs in case X is high'''
RESPONSE_INVOKE = 1
def __init__(self, parent, plugin_name, count):
title = ngettext('Run the plugin "%s" on %d song?', 'Run the plugin "%s" on %d songs?', count) % (plugin_name, count)
super(ConfirmMultiSongInvoke, self).__init__(get_top_parent(parent), title, '', buttons = Gtk.ButtonsType.NONE)
self.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL)
delete_button = Button(_('_Run Plugin'), Gtk.STOCK_EXECUTE)
delete_button.show()
self.add_action_widget(delete_button, self.RESPONSE_INVOKE)
self.set_default_response(Gtk.ResponseType.CANCEL)
def confirm(cls, parent, plugin_name, count):
'''Returns if the action was confirmed'''
resp = cls(parent, plugin_name, count).run()
return resp == cls.RESPONSE_INVOKE
confirm = classmethod(confirm)
class ConfirmMultiAlbumInvoke(WarningMessage):
'''Dialog to confirm invoking a plugin with X albums in case X is high'''
RESPONSE_INVOKE = 1
def __init__(self, parent, plugin_name, count):
title = ngettext('Run the plugin "%s" on %d album?', 'Run the plugin "%s" on %d albums?', count) % (plugin_name, count)
super(ConfirmMultiAlbumInvoke, self).__init__(get_top_parent(parent), title, '', buttons = Gtk.ButtonsType.NONE)
self.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL)
delete_button = Button(_('_Run Plugin'), Gtk.STOCK_EXECUTE)
delete_button.show()
self.add_action_widget(delete_button, self.RESPONSE_INVOKE)
self.set_default_response(Gtk.ResponseType.CANCEL)
def confirm(cls, parent, plugin_name, count):
'''Returns if the action was confirmed'''
resp = cls(parent, plugin_name, count).run()
return resp == cls.RESPONSE_INVOKE
confirm = classmethod(confirm)
class SongsMenuPluginHandler(PluginHandler):
def __init__(self, song_confirmer = None, album_confirmer = None):
'''custom confirmers for testing'''
self._SongsMenuPluginHandler__plugins = []
self._confirm_multiple_songs = ConfirmMultiSongInvoke.confirm
if song_confirmer is not None:
self._confirm_multiple_songs = song_confirmer
self._confirm_multiple_albums = ConfirmMultiAlbumInvoke.confirm
if album_confirmer is not None:
self._confirm_multiple_albums = album_confirmer
def Menu(self, library, parent, songs):
songs = ListWrapper(songs)
parent = qltk.get_top_parent(parent)
attrs = [
'plugin_song',
'plugin_songs',
'plugin_album',
'plugin_albums']
last = None if len(songs) == 1 else None
for song in songs:
if song.album_key != last.album_key:
break
last = song
items = []
kinds = self._SongsMenuPluginHandler__plugins
kinds.sort(key = (lambda plugin: plugin.PLUGIN_ID))
for Kind in kinds:
usable = max([ callable(getattr(Kind, s)) for s in attrs ])
if usable:
try:
items.append(Kind(songs, library, parent))
print_e("Couldn't initialise song plugin %s. Stack trace:" % Kind)
print_exc()
continue
items = filter((lambda i: i.initialized), items)
if items:
menu = Gtk.Menu()
for item in items:
try:
menu.append(item)
args = (library, parent, songs)
if item.get_submenu():
for subitem in item.get_submenu().get_children():
connect_obj(subitem, 'activate', self._SongsMenuPluginHandler__handle, item, *args)
else:
item.connect('activate', self._SongsMenuPluginHandler__handle, *args)
continue
print_exc()
item.destroy()
continue
else:
menu = None
return menu
def __get_albums(self, songs):
albums = { }
for song in songs:
key = song.album_key
if key not in albums:
albums[key] = []
albums[key].append(song)
albums = albums.values()
for album in albums:
album.sort()
return albums
def handle(self, plugin_id, library, parent, songs):
'''Start a song menu plugin directly without a menu'''
for plugin in self._SongsMenuPluginHandler__plugins:
if plugin.PLUGIN_ID == plugin_id:
songs = ListWrapper(songs)
try:
plugin = plugin(songs, library, parent)
except Exception:
print_exc()
self._SongsMenuPluginHandler__handle(plugin, library, parent, songs)
return None
def __handle(self, plugin, library, parent, songs):
if len(songs) == 0:
return None
if len(songs) == 1 and callable(plugin.plugin_single_song):
try:
ret = plugin.plugin_single_song(songs[0])
except Exception:
print_exc()
if ret:
return None
if callable(plugin.plugin_song):
total = len(songs)
if not total > plugin.MAX_INVOCATIONS and self._confirm_multiple_songs(parent, plugin.PLUGIN_NAME, total):
return None
try:
ret = map(plugin.plugin_song, songs)
except Exception:
print_exc()
if max(ret):
return None
if callable(plugin.plugin_songs):
try:
ret = plugin.plugin_songs(songs)
except Exception:
print_exc()
if ret:
return None
if plugin.handles_albums:
albums = self._SongsMenuPluginHandler__get_albums(songs)
total = len(albums)
if total > plugin.MAX_INVOCATIONS:
if not self._confirm_multiple_albums(parent, plugin.PLUGIN_NAME, total):
return None
if callable(plugin.plugin_single_album) and len(albums) == 1:
try:
ret = plugin.plugin_single_album(albums[0])
except Exception:
print_exc()
if ret:
return None
if callable(plugin.plugin_album):
try:
ret = map(plugin.plugin_album, albums)
except Exception:
print_exc()
if max(ret):
return None
if callable(plugin.plugin_albums):
try:
ret = plugin.plugin_albums(albums)
except Exception:
print_exc()
if ret:
return None
check_wrapper_changed(library, parent, filter(None, songs))
def plugin_handle(self, plugin):
return issubclass(plugin.cls, SongsMenuPlugin)
def plugin_enable(self, plugin):
self._SongsMenuPluginHandler__plugins.append(plugin.cls)
def plugin_disable(self, plugin):
self._SongsMenuPluginHandler__plugins.remove(plugin.cls)
class SongsMenu(Gtk.Menu):
plugins = SongsMenuPluginHandler()
def init_plugins(cls):
PluginManager.instance.register_handler(cls.plugins)
init_plugins = classmethod(init_plugins)
def __init__(self, library, songs, plugins = True, playlists = True, queue = True, devices = True, remove = True, delete = False, edit = True, parent = None):
super(SongsMenu, self).__init__()
librarian = getattr(library, 'librarian', library)
if plugins:
submenu = self.plugins.Menu(librarian, parent, songs)
if submenu is not None:
b = qltk.MenuItem(_('_Plugins'), Gtk.STOCK_EXECUTE)
self.append(b)
b.set_submenu(submenu)
self.append(SeparatorMenuItem())
in_lib = True
can_add = True
is_file = True
for song in songs:
if song not in library:
in_lib = False
if not song.can_add:
can_add = False
if not song.is_file:
is_file = False
continue
self.separate()
if playlists:
PlaylistMenu = PlaylistMenu
import quodlibet.browsers.playlists.menu
try:
submenu = PlaylistMenu(songs, parent)
except AttributeError:
e = None
print_w("Couldn't get Playlists menu: %s" % e)
b = qltk.MenuItem(_('Play_lists'), Gtk.STOCK_ADD)
b.set_sensitive(can_add)
b.set_submenu(submenu)
self.append(b)
if queue:
b = qltk.MenuItem(_('Add to _Queue'), Gtk.STOCK_ADD)
b.connect('activate', self._SongsMenu__enqueue, songs)
qltk.add_fake_accel(b, '<ctrl>Return')
self.append(b)
b.set_sensitive(can_add)
if devices:
browsers = browsers
import quodlibet
try:
browsers.media
except AttributeError:
pass
if browsers.media.MediaDevices in browsers.browsers:
submenu = browsers.media.Menu(songs, library)
b = qltk.MenuItem(_('_Copy to Device'), Gtk.STOCK_COPY)
if can_add:
pass
b.set_sensitive(len(submenu) > 0)
b.set_submenu(submenu)
self.append(b)
if remove or delete:
self.separate()
if remove:
b = qltk.MenuItem(_('_Remove from library'), Gtk.STOCK_REMOVE)
if callable(remove):
connect_obj(b, 'activate', remove, songs)
else:
b.connect('activate', self._SongsMenu__remove, songs, library)
b.set_sensitive(in_lib)
self.append(b)
if delete:
if callable(delete):
b = Gtk.ImageMenuItem(Gtk.STOCK_DELETE, use_stock = True)
connect_obj(b, 'activate', delete, songs)
else:
b = TrashMenuItem()
connect_obj(b, 'activate', trash_songs, parent, songs, librarian)
b.set_sensitive(is_file)
self.append(b)
if edit:
self.separate()
b = qltk.MenuItem(_('Edit _Tags'), Gtk.STOCK_PROPERTIES)
qltk.add_fake_accel(b, '<alt>Return')
def song_properties_cb(menu_item):
window = SongProperties(librarian, songs, parent)
window.show()
b.connect('activate', song_properties_cb)
self.append(b)
b = Gtk.ImageMenuItem(label = Gtk.STOCK_INFO, use_stock = True)
qltk.add_fake_accel(b, '<ctrl>I')
def information_cb(menu_item):
window = Information(librarian, songs, parent)
window.show()
b.connect('activate', information_cb)
self.append(b)
connect_obj(self, 'selection-done', Gtk.Menu.destroy, self)
def separate(self):
if not self.get_children():
return None
if not None(self.get_children()[-1], Gtk.SeparatorMenuItem):
self.append(SeparatorMenuItem())
def preseparate(self):
if not self.get_children():
return None
if not None(self.get_children()[0], Gtk.SeparatorMenuItem):
self.prepend(SeparatorMenuItem())
def __remove(self, item, songs, library):
library.remove(set(songs))
def __enqueue(self, item, songs):
songs = filter((lambda s: s.can_add), songs)
if songs:
app = app
import quodlibet
app.window.playlist.enqueue(songs)